Skip to content

[Logger] Support log4j-2.20+#471

Open
DriverSong wants to merge 1 commit intoray-project:masterfrom
DriverSong:support_log4j_2.20+
Open

[Logger] Support log4j-2.20+#471
DriverSong wants to merge 1 commit intoray-project:masterfrom
DriverSong:support_log4j_2.20+

Conversation

@DriverSong
Copy link
Copy Markdown

While log4j 2.20+ remove no-arg constructor from Log4jLoggerFactory and ray-2.54.0 use log4j 2.25.3, raydp should support the new constructor Log4jLoggerFactory(LoggerContext).

@slfan1989 slfan1989 requested a review from Copilot May 10, 2026 03:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the SLF4J binding initialization in RayDP’s agent to remain compatible with Log4j 2.20+, which removed the no-arg constructor from org.apache.logging.slf4j.Log4jLoggerFactory.

Changes:

  • Adds a reflective fallback path to instantiate Log4jLoggerFactory using the Log4jLoggerFactory(LoggerContext) constructor when no no-arg constructor is available.
  • Introduces reflection imports and logic to obtain a LoggerContext via LogManager.getContext(false).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 103 to +112
try {
tmpFactory = (ILoggerFactory) tempClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
// log4j 2.20+ removed the no-arg constructor from
// Log4jLoggerFactory. Fall back to the constructor that
// accepts a LoggerContext.
try {
Class<?> ctxClass = Class.forName(
"org.apache.logging.log4j.spi.LoggerContext");
Constructor<?> ctor = tempClass.getConstructor(ctxClass);
.invoke(null, false);
tmpFactory = (ILoggerFactory) ctor.newInstance(ctx);
} catch (Exception ex) {
e.printStackTrace();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants